import { request } from '../request';

/** 获取采购结算单列表
 * @param filterOption - 过滤选项
 */
export const fetchPurchaseList = async (filterOption?: any) => {
  if (filterOption) {
    const { billClass, billType, beginDate, endDate } = filterOption;
    const data = await request.post<null>('/getPurchaseList', {
      billClass,
      billType,
      beginDate,
      endDate
    });
    return data;
  }
  return request.post<null>('/getPurchaseList');
};

/** 获取采购结算单详情 */
export const fetchPurchaseDetail = async (billId: string) => {
  const data = await request.post<null>('/getPurchaseDetail', { billId });
  return data;
};

/** 获取采购结算明细 */
export const fetchPurchaseSettlementDetails = async (billId: string) => {
  const data = await request.post<null>('/getPurchaseSettlementDetails', {
    billId
  });
  return data;
};

/** 获取扣款项目 */
export const fetchPurchaseDeductionItems = async (billId: string) => {
  const data = await request.post<null>('/getPurchaseDeductionItems', {
    billId
  });
  return data;
};

/** 获取对账单
 * @param formOption - 表单选项
 */
export const fetchNewBill = async (formOption?: any) => {
  const { billClass, billType, beginDate, endDate } = formOption;
  return request.post<null>('/getNewBill', {
    billClass,
    billType,
    beginDate,
    endDate
  });
};

/** 批量删除明细账单
 * @param entryIds - 多张对账单ID字符串拼接
 */
export function fetchDeleteDetailBills(entryIds: string) {
  return request.post<null>('/deleteDetailBills', {
    entryIds
  });
}

/** 保存/提交对账单
 * @param type - 类型：0=保存 1=提交
 * @param billId - 对账单ID
 * @param billDatas - 提交的数据
 */
export function fetchSubmitBill(type: string, billId: string, billDatas: any) {
  const { billDate, billRemark } = billDatas;
  return request.post<null>('/submitBill', {
    type: type.toString(),
    billId: billId.toString(),
    billDate,
    billRemark: billRemark.toString()
  });
}

/** 刷新结算价
 * @param billId - 对账单ID
 */
export function fetchRefreshPrice(billId: string) {
  return request.post<null>('/refreshPrice', {
    billId
  });
}
